from django.shortcuts import render

# Create your views here.

from Vaccine.models import CategoryModels, VaccineModels
from Vaccine.ser import CategoryModelsSerializer, VaccineModelsSerializer

from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework.pagination import PageNumberPagination
from rest_framework.filters import OrderingFilter

# 分页配置
class StandardResultsSetPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    max_page_size = 100

# 排序配置
class CustomOrderingFilter(OrderingFilter):
    ordering_params = ('name',)

# 疫苗类别 ListAPIView
class CategoryModelsListView(ListAPIView):
    serializer_class = CategoryModelsSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['name']

    def get_queryset(self):
        return CategoryModels.objects.all()

# 疫苗信息 ListAPIView
class VaccineModelsListView(ListAPIView):
    serializer_class = VaccineModelsSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['name']

    def get_queryset(self):
        return VaccineModels.objects.all()

# 疫苗信息 RetrieveAPIView
class VaccineModelsDetailView(RetrieveAPIView):
    serializer_class = VaccineModelsSerializer
    queryset = VaccineModels.objects.all()
    lookup_field = 'id'